package birdsVSZombiesServer;

import com.google.gson.Gson;

import pbox2d.PBox2D;
import jbox2dprocessing.compontent.*;
import processing.net.Server;

import jbox2dprocessing.compontent.BaseBox;
import jbox2dprocessing.compontent.BaseCircle;
import jbox2dprocessing.compontent.BoundaryBox;
import shared.BVZConstants;
import shared.BVZServerToClientsMessages;

public class PhysicalSimulation extends Thread {
	
	public static BirdsVSZombiesServerThread parent;
	
	public PhysicalSimulation(){
		super();
	}
	
	public void run(){
		while(true){
			parent.box2d.step();
			
			for (int i = 0; i < parent.boundaries.size(); i++) {
				BoundaryBox bb = parent.boundaries.get(i);
//				bb.display();
			}
			
			//		Display the PhysCircles
			for (int i = 0; i < parent.circles.size(); i++) {
				BaseCircle c = (BaseCircle)parent.circles.get(i);
//				c.display();
			}
			
			for (int i = 0; i < parent.boxes.size(); i++) {
				BaseBox b = (BaseBox)parent.boxes.get(i);
//				b.display();
			}
			
			//		Make a snap shot of the scene
			parent.testTimer++;
			BVZServerToClientsMessages msg = new BVZServerToClientsMessages(parent.testTimer, BVZConstants.SERVERRUNPHYS, parent.boundaries, parent.circles, parent.boxes);
			String msgJson = parent.gson.toJson(msg) + "*";
//			println("send!!!!!");
					
			parent.bvzServer.write(msgJson);
//			parent.println(msgJson);

		}
	}
}
